

import {defineStore} from 'pinia';

const store = {
    id: "home",
    state(){
        return{
            deviceCount: 0,
            alarmCount: 0,
            customerCount: 0,
        }
    },

    getters: {

    },

    actions: {
        async getList(keyword) {
            let params = {};
            if(! Helper.empty(keyword)) {
                params.keyword = keyword;
            }
            Msg.loading("加载中...");
            let {code, data} = await Http.get("/map/marker/list", params);
            Msg.loading(false);
            if(code == 200) {
                return data;
            }

            return [];
        },

        async countDevice(type, model) {
            let params = {};
            if(! Helper.empty(type)) {
                params.type = type;
            }

            if(Helper.empty(model)) {
                params.model = model;
            }

            let {code, data} = await Http.get("/device/count", params);
            if(code == 200) {
                this.deviceCount = data;
                return data;
            }
            return 0;
        },

        async countCustomer() {
            let {code, data} = await Http.get("/customer/count");
            if(code == 200) {
                this.customerCount = data;
                return data;
            }
            return 0;
        },

        async countAlarm() {
            let {code, data} = await Http.get("/alarm/count");
            if(code == 200) {
                this.alarmCount = data;
                return data;
            }
            return 0;
        }
    }
}

export default defineStore(store)
